package com.wink_172.library.view;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;
import android.widget.Toast;

import com.wink_172.library.R;


public class CustomToast {

    private static Toast toastStart;

    public static void showToast(Context context, String message) {

        View root = LayoutInflater.from(context).inflate(R.layout.custom_toast, null);
        TextView textView = (TextView) root.findViewById(R.id.text_view);
        textView.setText(message);

        toastStart = new Toast(context);
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        int height = wm.getDefaultDisplay().getHeight();
        //Toast的Y坐标是屏幕高度的1/3，不会出现不适配的问题
        toastStart.setGravity(Gravity.CENTER, 0, 0);
        toastStart.setDuration(Toast.LENGTH_SHORT);

        toastStart.setView(root);
        toastStart.show();
    }
}
